﻿using System;

namespace KPIS.GERP.Models.Class
{
	public static class CompareUtility
	{
		/// <summary>
		/// Compare two string parameter, make lower before compare
		/// </summary>
		/// <param name="str1">Param #1 to compare</param>
		/// <param name="str2">Param #2 to compare</param>
		/// <returns>Result of compare</returns>
		public static bool IsStringsEqual(string str1, string str2)
		{
			str1 = ConvertUtility.MakeStringEmptyAndLower(str1);
			str2 = ConvertUtility.MakeStringEmptyAndLower(str2);
			return str1.Equals(str2);
		}

		/// <summary>
		/// Convert any types to string (if null get empty string) and then compare both param by string
		/// </summary>
		/// <param name="obj1">Param #1 to compare</param>
		/// <param name="obj2">Param #2 to compare</param>
		/// <returns>Result of compare</returns>
		public static bool IsObjectToStringEqual(object obj1, object obj2)
		{
			obj1 = ConvertUtility.MakeStringEmptyAndLower(obj1 == null ? string.Empty : obj1.ToString());
			obj2 = ConvertUtility.MakeStringEmptyAndLower(obj2 == null ? string.Empty : obj2.ToString());
			return obj1.Equals(obj2);
		}
         
        public static int GetYears(this TimeSpan timespan)
        {
            return (int)((double)timespan.Days / 365.2425);
        }
        public static int GetMonths(this TimeSpan timespan)
        {
            return (int)((double)timespan.Days / 30.436875);
        } 
	}
}
